<template>
  <div class="tab-bar">
    <router-link to="/" class="tab-item" :class="{ active: $route.path === '/' }">
      <img :src="isActive('/') ? require('@/assets/img/homeing.png') : require('@/assets/img/home.png')" alt="首页">
      <span>首页</span>
    </router-link>
    <router-link to="/category" class="tab-item" :class="{ active: $route.path === '/category' }">
      <img :src="isActive('/category') ? require('@/assets/img/categorying.png') : require('@/assets/img/category.png')" alt="分类">
      <span>分类</span>
    </router-link>
    <router-link to="/cart" class="tab-item" :class="{ active: $route.path === '/cart' }">
      <img :src="isActive('/cart') ? require('@/assets/img/carting.png') : require('@/assets/img/cart.png')" alt="购物车">
      <span>购物车</span>
    </router-link>
    <router-link to="/my" class="tab-item" :class="{ active: $route.path === '/my' }">
      <img :src="isActive('/my') ? require('@/assets/img/mying.png') : require('@/assets/img/my.png')" alt="我的">
      <span>我的</span>
    </router-link>
  </div>
</template>

<script>
export default {
  name: 'TabBar',
  methods: {
    isActive(path) {
      return this.$route.path === path;
    }
  }
};
</script>

<style scoped>
.tab-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-top: 1px solid #ebebeb;
  background-color: #fff;
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
}

.tab-item {
  font-size: 14px;
  height: 50px;
  text-decoration: none;
  color: #7d7d7d;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
}

.tab-item img {
  width: 20px;
  height: 20px;
}

.active {
  color: #c03131;
}
</style>